/**
 * Created by user on 2018/11/7.
 */
import {Route, Redirect} from "dva/router";
import React from "react";
import Authorized from "./Authorized";

class PrivateRoute extends React.Component {
  render() {
    const {component: Component, render, redirect, authority, ...rest} = this.props
    return (
      <Authorized
        authority={authority}
        noMatch={<Route {...rest} render={props => <Redirect to={{pathname: redirect}}/>}/>}
      >
        <Route
          {...rest}
          render={props => Component ? <Component {...props}/> : render(props)}
        />
      </Authorized>
    )
  }
}

export default PrivateRoute
